package com.island.gomall.dao;

import com.island.gomall.entity.CategoryEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author MarkTien
 * @Mail marktien@foxmail.com
 **/
@Repository
public interface CategoryDao {

    @Select("SELECT id as catId,name,parent_id as parentCid,level as catLevel,show_status as showStatus,sort,icon,unit as productUnit,count as productCount FROM product_category")
    List<CategoryEntity> selectList();
    @Select("SELECT count(id) FROM product_category WHERE parent_id = #{cid}")
    int isExistChildern(int cid);
    @Update("UPDATE product_category SET show_status = 1 WHERE id = #{cid}")
    void logicDelete(int cid);
    @Insert("INSERT INTO product_category (name,parent_id) VALUES (#{name},(SELECT COUNT(id) FROM product_category WHERE parent_id = #{parentId})+1")
    void insertCategoryNode(@Param("parentId") int parentId, @Param("name") String name);
}
